<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>新增系统操作</title>
	<base href="<%=basePath%>"/>
	<%@ include file="../../cuv_include.jsp"%>
	<style type="text/css"> 
	  fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
	  form label {font-weight:bold;}
	  table{margin:10px 10px};
	  td{line-height: 40px;}
	  input[type="text"]{width:250px;}
	  input[type="password"]{width:250px;}
	  input[type="textarea"]{width:250px;}
	</style>

<script type="text/javascript">
  $(document).ready(function(){
      $("#enname").focus();
      
      var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
      $("#actionForm").submit(function(){
    	  $("#btn_insert").attr("disabled","disabled");
          $(this).ajaxSubmit(options);
          return false;
      });
  });
  
  function beforeSubmit() {
      if(isEmpty($("#enname").val())) { alert("英文名称不能为空！"); 
      	$("#btn_insert").removeAttr("disabled");
      	return false; }
      
      if(!validateEnName($("#enname").val(), 6, 32)) { alert("英文名不符合规格！"); 
      	$("#btn_insert").removeAttr("disabled");
      	return false; }
      
      if(isEmpty($("#alias").val())) { alert("别名不能为空！"); 
      	$("#btn_insert").removeAttr("disabled");
      	return false; }
      
      if(!validateSize($("#alias").val(), 2, 32)) { alert("别名不符合规格！"); 
      	$("#btn_insert").removeAttr("disabled");
      	return false; }	
      
      if(isEmpty($("#url").val())) { alert("url不能为空！"); 
      	$("#btn_insert").removeAttr("disabled");
      	return false; }	 
      
      return true;
  }
  
  function process(responseJson) {
	  $("#btn_insert").removeAttr("disabled");
      if(responseJson.code == 0) {
          $('#error_label').text("错误信息：" + responseJson.message);
          $("#p_error").show();
          return;
      }
      var qs = $("#qs").val();
      location.href = "<%=basePath%>system/action/list.do?" + qs;	  
  }  
</script>
</head>
<body>
  <div>
    <fieldset>
      <legend>新增操作：</legend>
      <form id="actionForm" method="post" action="system/action/insert.do">
      	<input id="qs" name="qs" type="hidden" value="${qs}"/>
      	<p id = "p_error" style = "margin:10px 10px;">
      	    <label id="error_label" style="color:red;"></label>
      	</p>
        <table>
          <tr>
            <td><label>所属模块：</label></td>
            <td>
                <select id="moduleName" name="moduleName" style="width:250px;">
                <c:forEach var="module" items="${moduleList}" varStatus="status">
                	<option value="${module.enname}" <c:if test="${module.enname eq action.moduleName}">selected='selected'</c:if> >${module.alias}</option>
                </c:forEach>
              	</select> 
                <font color="red">&nbsp;*&nbsp;&nbsp;</font>
            </td>
          </tr>          
          <tr>
            <td><label for="enname">英文名称：</label></td>
            <td>
            	<input type="text" name="enname" id="enname" value="${action.enname }" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="enname">只能由字母、数字、下划线组成，字母开始，6～32位</label>
            </td>
          </tr>
          <tr>
            <td><label for="alias">别名：</label></td>
            <td>
            	<input type="text" name="alias" id="alias" value="${action.alias }" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="alias">可以是中文，2～32位</label>
            </td>
          </tr>          
          <tr>
            <td><label for="url">URL：</label></td>
            <td>
            	<input type="text" name="url" id="url" value="${action.url }" style="width:400px;" />
                <font color="red">&nbsp;*&nbsp;&nbsp;</font>
            </td>
          </tr>
          <tr>
            <td valign="top"><label for="remark">描述：</label></td>
            <td valign="top"><textarea name="remark" id="remark" cols="40" rows="3"><c:out value="${action.remark }"/></textarea></td>
          </tr>                   
          <tr>
            <td></td>
            <td>
            	<input type="submit" id="btn_insert" value="提交" style="width:80px;" />
            	<input type="button" id="btn_back" value="返回" onclick="history.back();" style="width:80px;" />
            </td>
          </tr>
        </table>
      </form>
    </fieldset>
  </div>
</body>
</html>